<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./vue.js"></script>
    <script src="./vue-router.js"></script>
    <style>
        /* 当 <router-link>标签被激活时 添加类样式*/
        .active{
            background-color: pink;
            font-size: 30px;
            color: skyblue;
        }

        .v-enter,
        .v-leave-to{
            opacity: 0;
            transform: translateX(140px); 
        }

        .v-enter-active,
        .v-leave-active{
            transition: all 0.2s ease;
        }
    </style>
</head>
<body>
    <div class="" id="app">
        <!-- 不需要输入属性名 id/name -->
        <router-link to="/login/10/ls" tag="span">登录</router-link>
        <router-link to="/register" tag="span">注册</router-link>
        <transition mode="out-in">
            <router-view></router-view>
        </transition>

    </div>
    <script>
        var login = {
            // 此时参数不在 query  而是在 params
            template:"<h1>登录---{{this.$route.params.id}}-----{{this.$route.params.name}}</h1>",
            // 组件的生命周期钩子函数
            created(){
                console.log(this.$route.params.id);
            }
        }
        var register = {
            template:"<h1>注册</h1>",
        }
        var routerObj = new VueRouter({
            routes:[
                {path:"/",redirect:"/login"},
                // 路由规定了  跳转到/login  必须得提交 id和name  否则不显示页面
                {path:"/login/:id/:name",component:login},
                {path:"/register",component:register}
            ],
            linkActiveClass:"active"
        });

        var vm = new Vue({
            el:"#app",
            data:{},
            methods:{},
            router:routerObj,
        })
    </script>
</body>
</html>